package com.foreknow.controller;

import com.foreknow.entity.User;
import com.foreknow.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class AddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter out = resp.getWriter();
        String username =req.getParameter("username");
        String account =req.getParameter("account");
        String password =req.getParameter("password");
        String phone =req.getParameter("phone");
        String email =req.getParameter("email");
        String avater =req.getParameter("avater");
        UserService service = new UserService();
        User user = new User();
        user.setUsername(username);
        user.setPhone(phone);
        user.setEmail(email);
        user.setAccount(Integer.parseInt(account));
        user.setAvater(avater);
        user.setPassword(password);

        boolean isOK= service.insert(user);
        if(isOK){
            out.println("添加成功");
        }else{
            out.println("添加失败");
        }
    }
}
